#include "mainsence.h"
#include "ui_mainsence.h"
#include<QPainter>
#include<QDebug>
#include"mypushbutton.h"
#include<QTimer>
#include<QSound>
MainSence::MainSence(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainSence)
{
    ui->setupUi(this);

    //日常场景设置
    this->setFixedSize(320,588);
    this->setWindowIcon(QPixmap(":/res/Coin0001.png"));
    this->setWindowTitle("YourFather");

    connect(ui->actionQuit,&QAction::triggered,[=](){
       this->close();
    });

    //准备开始按钮的音效
    QSound *startSound=new QSound(":/res/TapButtonSound.wav",this);

    startSound->setLoops(10);//设置音效循环，如果是-1代表无限循环。
    startSound->play();

    //开始按钮
    MyPushButton* startBtn=new MyPushButton(":/res/MenuSceneStartButton.png");
    startBtn->setParent(this);
    startBtn->move(this->width()*0.5-startBtn->width()*0.5,this->height()*0.7);

    chooseScene=new ChooseLevelScene;

    //监听选择关卡按钮的信号
    connect(chooseScene,&ChooseLevelScene::chooseSceneBack,this,[=](){
        this->setGeometry(chooseScene->geometry());
        chooseScene->hide();
        this->show();
    });

    connect(startBtn,&MyPushButton::clicked,[=](){

        //播放音效资源
        startSound->play();
        //弹起的特效
        startBtn->zoom1();
        startBtn->zoom2();

        //延时进入到选择场景
        QTimer::singleShot(500,this,[=](){
            //设置一下chooseScene场景的位置
            chooseScene->setGeometry(this->geometry());
            this->hide();
            chooseScene->show();
            //监听选择关卡的返回按钮的信号

//            connect(chooseScene,&ChooseLevelScene::chooseSceneBack,this,[=](){
//                chooseScene->hide();
//                this->show();
//            });

        });
        //进入到选择关卡
        //自身隐藏，显示选择关卡的场景
        //this->hide();
       // chooseScene->show();

    });

}

void MainSence::paintEvent(QPaintEvent *){

    QPainter painter(this);
    QPixmap pix;
    pix.load(":/res/PlayLevelSceneBg.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);

    pix.load(":/res/Title.png");
    pix=pix.scaled(pix.width()*0.5,pix.height()*0.5);
    painter.drawPixmap(10,30,pix.width(),pix.height(),pix);

    //qDebug()<<pix.width()<<pix.height();


}

MainSence::~MainSence()
{
    delete ui;
}
